package com.bw.day_2.park

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.CalendarContract.Instances.END
import android.view.Gravity
import androidx.appcompat.widget.SearchView.OnQueryTextListener
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.base.mvvm.BaseActivity
import com.bw.base.mvvm.BaseViewActivity
import com.bw.day_2.R
import com.bw.day_2.adapter.ParkAdapter
import com.bw.day_2.databinding.ActivityParkBinding
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
@Route(path = "/app/ParkActivity")

class ParkActivity : BaseActivity<ActivityParkBinding,ParkViewModel>() {
    var parkAdapter = ParkAdapter()
    var aid = "0"
    @SuppressLint("WrongConstant")
    override fun initView() {
        //添加车位信息
        binding.add.setOnClickListener {
            ARouter.getInstance().build("/app/AddParkActivity").navigation()
        }
        //返回上一页
        binding.back.setOnClickListener {
            finish()
        }

        binding.sv.setOnQueryTextListener(object :OnQueryTextListener{
            override fun onQueryTextSubmit(query: String?): Boolean {
                    aid=query!!
                    viewModel.park(aid.toInt())
                return true
            }

            override fun onQueryTextChange(newText: String?): Boolean = true

        })
        binding.rbKx.setOnClickListener {
            viewModel.parkStatus("空闲")
        }
        binding.rbZy.setOnClickListener {
            viewModel.parkStatus("已占用")
        }
        binding.rbWh.setOnClickListener {
            viewModel.parkStatus("维护中")
        }

        binding.parkRv.adapter = parkAdapter

        viewModel.park(1)

        binding.lou.setOnClickListener {
            binding.drawer.openDrawer(Gravity.END)
        }
    }

    override fun initData() {
        viewModel.parkSuccess.observe(this){
            parkAdapter.data.clear()
            parkAdapter.data.addAll(it)
            parkAdapter.notifyDataSetChanged()
        }
        viewModel.parkStatusSuccess.observe(this){
            parkAdapter.data.clear()
            parkAdapter.data.addAll(it)
            parkAdapter.notifyDataSetChanged()
        }
    }
}